package com.thb.pay.comm.config;

import com.xiaoleilu.hutool.util.StrUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "payment.config")
public class PayConfig {

    private String notifyUrl;  // 后台异步通知地址

    private String returnUrl;  // 前端同步跳转地址

    private String notifyTransUrl;  // 转账异步通知地址

    private String certRootPath; // 证书根路径

    private String payUrl; // 支付中心url

    private String notifyDivisionUrl; // 分账异步通知接口

    public String getJumpUrl() {
        return payUrl + "/jump.htm";
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public String getNotifyUrl(String channelName) {
        if (StrUtil.isBlank(channelName)) return getNotifyUrl();
        return String.format(notifyUrl, channelName);
    }


    public String getReturnUrl(String channelName) {
        if (StrUtil.isBlank(channelName)) return getReturnUrl();
        return String.format(returnUrl, channelName);
    }

    public String getNotifyTransUrl(String channelName) {
        if (StrUtil.isBlank(channelName)) return getNotifyTransUrl();
        return String.format(notifyTransUrl, channelName);
    }


    public String getNotifyDivisionUrl(String channelName) {
        if (StrUtil.isBlank(channelName)) return getNotifyDivisionUrl();
        return String.format(notifyDivisionUrl, channelName);
    }

}

